<?php
require ('../include/init.inc.php');
$method = $machine_id = '';
extract ( $_GET, EXTR_IF_EXISTS );
if (Common::isPost ()) {
	
	$update_data =$_POST;
	$machine_id = $update_data["machine_id"];
	$update_data["area_code_num"] = substr(trim($update_data["custom_code"]),0,1);
	$update_data["company_code_num"] = substr(trim($update_data["custom_code"]),2,3);
	$result = Machine::updateMachineInfo ( $machine_id,$update_data );
	
	if ($result>=0) {
		SysLog::addLog ( UserSession::getUserName(), 'UPDATE', 'Machine' ,$machine_id, json_encode($update_data) );
		Common::exitWithSuccess ('主机更新完成','panel/machine.php');
	} else {
		OSAdmin::alert("error");
	}
	
}
if($method == 'modify' && ! empty ( $machine_id )) {
	$machine = Machine::getMachineById($machine_id);
	
	$machine["check_1"] =  $machine["sales_type"] == '1'?"checked":'';
	$machine["check_2"] =  $machine["sales_type"] == '2'?"checked":'';
	$condition  = " where machine_id=".$machine_id; 
	$allmachineRemark = MachineRemark::getAllMachineRemark($condition);	
	
	$allmachineVistor =  MachineVistor::getAllMachineVistor($condition);	
	
	$allmachineConsumables =  MachineConsumables::getAllMachineConsumables($condition);
	$allConsumablesRemark  =  MachineConsumablesRemark::getAllMachineConsumablesRemark($condition);
	$allAccessoriesRemark  =  MachineAccessoriesRemark::getAllMachineAccessoriesRemark($condition);
	$allMachineContract  =  MachineContract::getAllMachineContract($condition);
	$allMachineContractRemark  =  MachineContractRemark::getAllMachineContractRemark($condition);
}
Template::assign ( 'machineRemark', $allmachineRemark );
Template::assign ( 'machineVistor', $allmachineVistor );
Template::assign ( 'machineConsumables', $allmachineConsumables );
Template::assign ( 'machineConsumablesRemark', $allConsumablesRemark );
Template::assign ( 'machineAccessoriesRemark', $allAccessoriesRemark );
Template::assign ( 'machineMachineContract', $allMachineContract );
Template::assign ( 'machineMachineContractRemark', $allMachineContractRemark );
Template::assign ( 'method', $method );
Template::assign ( 'machine_id', $machine_id );
Template::assign ( '_POST', $machine );
Template::display ( 'panel/machine_add.tpl' );
